package com.itheima.demo3character;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class CharSetDemo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
//        1、写程序实现字符编码和解码
        String str="我爱你中国sda66";
//        byte[] bytes=str.getBytes();//平台的UTF-8字符集编码
        byte[] bytes=str.getBytes("GBK");//平台的UTF-8字符集编码
        System.out.println(bytes.length);
        System.out.println(Arrays.toString(bytes));
//        2、解码
        String s=new String(bytes,"GBK");//指定GBK解码
        System.out.println(s);
    }
}
